package com.example.demo.Client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
    private Socket clientSocket;
    private PrintWriter out;
    private BufferedReader in;
    private String account;
    private int port;

    public void setAccount(String account) {
        this.account = account;
    }
    public String getAccount(){
        return this.account;
    }
    public int getPort(){
        return port;
    }

    public Socket getClientSocket() {
        return clientSocket;
    }

    public void startConnection(String ip, int port) throws IOException {
        clientSocket = new Socket(ip,port);
        this.port = clientSocket.getPort();
        out = new PrintWriter(clientSocket.getOutputStream(),true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    }
    public void stopConnection(){
        try {
            in.close();
            out.close();
            clientSocket.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }


}
